<?php if (!defined("_ECRIRE_INC_VERSION")) return;
/**
 * Aloha Cart
 *
 * @author     Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 * @license    GNU/GPL
 * @package    plugins
 * @subpackage alohacart
 * @copyright  (c) Aleksey Yaroshchuk 2011-2012
 * @link       http://www.spip-contrib.net/AlohaCart
 */

include_spip('functions/pdk_common');

function formulaires_alohacart_orders_excel_download_traiter_dist(){
	$orders_ex = pdk_load_class('AlohacartOrdersExcel', 'classes/order');
    if (_request('id_statut'))
        $orders_ex->OrderIdStatut = _request('id_statut');
    if (_request('date_from'))
        $orders_ex->OrderDateFrom = convert_spip_date_to_mysql_date(_request('date_from'));
    if (_request('date_to'))
        $orders_ex->OrderDateTo = convert_spip_date_to_mysql_date(_request('date_to'));
    $orders_ex->OutputFile();
}

function convert_spip_date_to_mysql_date($date) {
    preg_match('/([0-9]+)\/([0-9]+)\/([0-9]+)/', $date, $matches);
    if (!$matches[1] || !$matches[2] || !$matches[3]) return false;
    $day = $matches[1];
    $month = $matches[2];
    $year = $matches[3];
            
    $unix_date = strtotime("$month/$day/$year");
        
    return date('Y-m-d', $unix_date);
}
